package com.itheima;

import com.mongodb.BasicDBObject;
import com.mongodb.client.*;
import org.bson.Document;

public class MongoDriverDemo {

    public static void main(String[] args) {
        //1.跟MongoDB建立连接 得到MongoClient对象
        MongoClient mongoClient = MongoClients.create("mongodb://127.0.0.1:27017");
        //2.通过MongClient对象获取数据库
        MongoDatabase database = mongoClient.getDatabase("test");

        //3.通过集合（表）获取文档
        MongoCollection<Document> collection = database.getCollection("user");

        //4.处理数据
        BasicDBObject basicDBObject = new BasicDBObject();
        basicDBObject.append("username", "lisi");
        FindIterable<Document> documents = collection.find(basicDBObject).skip(0).limit(10);

        for (Document document : documents) {
            System.out.println(document.toString());
        }
        //5.关闭连接
        mongoClient.close();
    }
}
